﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using TEL.ClientClasses;
using TEL.ClientClasses.Private;
using TEL.ClientClasses.SipInterfaces;
using TEL.TelPhoneF.Dialogs;

namespace TEL.TelPhoneF
{
    class Setting
    {
        public static void VersionUpdate()
        {
            if (Properties.Settings.Default.IsNewVersion)
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.IsNewVersion = false;
                Properties.Settings.Default.Save();
            }
        }

        public ISipAccount LoadContent(bool isEditDialog)
        {
            ISipAccount sipProperty = null;
            if (isEditDialog)
            {
                sipProperty = new DialogSipAccount();
            }
            else
            {
                sipProperty = new SipProperty();
            }
            
            sipProperty.UserNumder = Properties.Settings.Default.UserNumder;
            sipProperty.UserName = Properties.Settings.Default.UserName;
            sipProperty.Password = Properties.Settings.Default.Password;
            sipProperty.Host = Properties.Settings.Default.Host;
            sipProperty.Port = Properties.Settings.Default.Port;
            sipProperty.Transport = Properties.Settings.Default.Transport;
            sipProperty.SRTP = Properties.Settings.Default.SRTP;

             return sipProperty;
        }

        public bool SaveContent(ISipAccount sipProperty)
        {
            Properties.Settings.Default.UserNumder = sipProperty.UserNumder.Trim();
            Properties.Settings.Default.UserName = sipProperty.UserName.Trim();
            Properties.Settings.Default.Password = sipProperty.Password.Trim();
            Properties.Settings.Default.Host = sipProperty.Host.Trim();
            Properties.Settings.Default.Port = sipProperty.Port;
            Properties.Settings.Default.Transport = sipProperty.Transport;
            Properties.Settings.Default.SRTP = sipProperty.SRTP;
            Properties.Settings.Default.Save();
            return true;
        }

        public static bool CheckSipSetting()
        {
            if (string.IsNullOrEmpty(Properties.Settings.Default.UserNumder)) return false;
            if (string.IsNullOrEmpty(Properties.Settings.Default.UserName)) return false;
            if (string.IsNullOrEmpty(Properties.Settings.Default.Host)) return false; ;
            return true;
        }

    }
}